export const mounted = (el, binding) => {
  const callback = binding.value;
  const debounce = binding.arg || 200;
  const options = binding.modifiers || { passive: true };

  let debounceTimeout = null;
  const onResize = () => {
    clearTimeout(debounceTimeout);
    debounceTimeout = setTimeout(callback, debounce, options);
  }

  window.addEventListener('customResize', onResize);
  window.addEventListener('resize', onResize);

  el._onResize = { onResize, options };
};

export const unmounted = (el) => {
  const { onResize, options } = el._onResize;
  window.removeEventListener('customResize', onResize, options);
  window.removeEventListener('resize', onResize, options);
  delete el._onResize;
};